import {
    getUserSig
} from "../../requestApi/user";

const common = {
    state: {
        // 接诊状态 1.待诊 3.接诊中未视频 4.接诊中已视频 2.停诊 5.已结束视频但未结束问诊 6.用户拨打过来了医生未接听
        STATE: null,
        // 登录状态 1.未登录 2.登录中 3.登录成功 4.登录失败 5.登出中 6.登出成功 7.登出失败  
        TIMLOING_STATE: null,
        // 医生登录的id
        DoctorId: null,
        // 医生登录的Sig
        DoctorSig: "",
        // SDKAppID: 1400348670 // 预生产/生产
        SDKAppID: "1400340117" // 开发/测试
    },

    mutations: {
        SET_STATE: (state, options) => {
            state.STATE = options;
        },
        SET_DOCTOR: (state, options) => {
            state.DoctorId = options
        },
        SET_SIG: (state, options) => {
            state.DoctorSig = options;
        },
        SET_TIMLOING_STATE: (state, options) => {
            state.TIMLOING_STATE = options;
        }
    },

    actions: {
        GET_STATE({commit}, data) {
            commit("SET_STATE", data);
        },
        // 修改医生id
        GET_DOCTOR({ commit }, data) {
            commit("SET_DOCTOR", data);
        },
        // 获取腾讯IM sig
        GET_SIG({ commit }, data) {
            return new Promise((resolve, reject) => {
                getUserSig({
                    userId: data
                }).then(response => {
                    if (response.code == 200 && response.data && response.data.userSig) {
                        localStorage.setItem("SIG", response.data.userSig);
                        commit("SET_SIG", response.data.userSig);
                        resolve(response)
                    } else {
                        reject('error')
                    }
                }).catch(error => {
                    reject(error)
                })
            })
        },
        // 修改腾讯云状态
        GET_TIMLOING_STATE({commit}, data) {
            commit("SET_TIMLOING_STATE", data);
        },
        // 修改腾讯云状态
        CHANGE_SET_SIG({commit}, data) {
            commit("SET_SIG", data);
        },
    }
};

export default common;